package com.mt.mtbusinessmanagementsystem.mapper;

import com.mt.mtbusinessmanagementsystem.pojo.dto.CustomerDTO;
import com.mt.mtbusinessmanagementsystem.pojo.dto.DeptDTO;
import com.mt.mtbusinessmanagementsystem.pojo.dto.EmployeeDTO;
import com.mt.mtbusinessmanagementsystem.pojo.dto.LoginDTO;
import com.mt.mtbusinessmanagementsystem.pojo.entity.*;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;


@Mapper
public interface GeneralMapper {

    LoginDTO login(Employee employee);

    Integer isExistDept(Dept dept);
    @Insert("insert into dept(dept_name, employee_id) values (#{deptName},#{employeeId})")
    void insertDept(Dept dept);
    @Select("select posts_id from posts where posts_name=#{postName}")
    Integer getPostID(String postName);

    void updateEmployeeInfo(Employee employee);


    ArrayList<Employee> employeeByDept(Integer deptId);
    @Select("select dept_id from dept where dept_name=#{notAssignedDept}")
    Integer getDeptID(@Param("notAssignedDept") String notAssignedDept);
    @Update("update employee set dept_id=#{newDeptId} where dept_id=#{oldDeptId}")
    void updateEmployeeDeteId(@Param("oldDeptId") Integer oldDeptId,@Param("newDeptId") Integer newDeptId);
    @Delete("delete from dept where dept_id=#{deptId}")
    void delDept(@Param("deptId") Integer deptId);

    Employee getEmployee(Employee employee);
    @Select("select dept_id, dept_name, employee_id from dept where dept_name=#{deptName}")
    Dept getDept(@Param("deptName") String deptName);

    void updateDeptInfo(Dept dept);
    @Select("select emp.dept_id,emp.dept_name,emp.employee_id,employee.employee_name,count\n " +
            "from employee,(select dept.dept_id, dept.dept_name,dept.employee_id,count(employee.dept_id) as count from dept,employee where dept.dept_id=employee.dept_id group by employee.dept_id) as emp\n " +
            "where emp.employee_id=employee.employee_id")
    ArrayList<DeptDTO> deptInfoByList();
    @Insert("insert into posts(posts_name) values (#{postsName})")
    void insertPost(@Param("postsName") String postsName);

    void addEmployee(EmployeeDTO employeeDTO);

    ArrayList<EmployeeDTO> queryEmployeeList(EmployeeDTO employeeDTO);
    @Select("select company_id, company_name, company_people_number from company where company_name=#{companyName}")
    Company getCompany(@Param("companyName") String companyName);
    @Insert("insert into company(company_name, company_people_number) values (#{companyName},#{companyPeopleNumber})")
    void addCompany(CustomerDTO customerDTO);

    void addCustomer(CustomerDTO customerDTO);

    ArrayList<CustomerDTO> queryCustomerList(CustomerDTO customerDTO);
    @Select("select distinct customer.create_employee_id,employee_name from customer,employee where customer.create_employee_id=employee.employee_id")
    ArrayList<CustomerDTO> queryCreateInfo();
    @Select("select distinct customer.employee_id,employee_name from customer,employee where customer.employee_id=employee.employee_id")
    ArrayList<CustomerDTO> queryResponsibleInfo();

    void customerPut(Customer customer);
    @Insert("insert into follow(employee_id, customer_id, start_date)" +
            "values (#{employeeId},#{customerId},#{startDate})")
    void addFollow(Follow follow);
    @Select("select follow_id, employee_id, customer_id, start_date from follow where customer_id=#{customerId}")
    Follow getFollow(@Param("customerId") String customerId);

    void followPut(Follow follow);

    void delCustomer(CustomerDTO customerDTO);
    @Select("select * from customer where id=#{id}")
    CustomerDTO getCustomer(Integer id);

    CustomerDTO customerDetailedInfo(CustomerDTO customerDTO);

    FollowMethod getFollowMethod(FollowMethod followMethod);
    @Insert("insert into follow_method(follow_method) values (#{followMethod})")
    void addFollowMethod(FollowMethod followMethod);
    @Delete("delete from follow_method where follow_methods_id=#{followMethodId}")
    void delFollowMethod(@Param("followMethodId") Integer followMethodId);
}
